import absevnt from '../abseventsvc.js'
import rightmenumainaction from './RMouseAction/rightmenumainaction.js'
import utilfuncs from '../../canvas/common/tools/utilfuncs.js';
var funcs = utilfuncs.UtilFuncs;

class RMosUpSelGraphSvc extends absevnt.IEventSvc {
    constructor() {
        super();
    }
    act(canvasEvt) {
        console.log("RMosUpSelGraphSvc:xxx---------");
        let clickRightHtml = document.getElementsByClassName('clickRightMenu')[0];

        while (clickRightHtml.firstChild) {
            clickRightHtml.removeChild(clickRightHtml.lastChild);
        }

        this.createRMenu(clickRightHtml, canvasEvt);
        clickRightHtml.style.display = "block";
        clickRightHtml.style.left = canvasEvt.scrnx + "px";
        clickRightHtml.style.top = canvasEvt.scrny + "px";
        window.mainctl.forbidMouseMove = true;
    }

    createRMenu(clickRightHtml, canvasEvt) {
        this.addItem(clickRightHtml, "finish","结束");
        this.addItem(clickRightHtml, "close","闭合");
        this.addItem(clickRightHtml, "delete","删除");
        this.addItem(clickRightHtml, "copy","复制");
        this.addItem(clickRightHtml, "paste","粘贴");
        if (!canvasEvt.lock) {
            this.addItem(clickRightHtml, "lock","锁定");
        }
        else {
            this.addItem(clickRightHtml, "unlock","解锁");
        }

        if (funcs.isMoldGraph32(canvasEvt.type)){
            this.addItem(clickRightHtml, "explode","分解");
        }

        this.addItem(clickRightHtml, "makeSymbol","制造为模具");
        this.addItem(clickRightHtml, "generateIcon2Local","生成本地图标");
        if (canvasEvt.selMultiGraphFlag){
            this.addItem(clickRightHtml, "combine","组合");//组合
        }
        this.addItem(clickRightHtml, "editprop","属性样式");
        this.addItem(clickRightHtml, "xlink","链接");
        this.addItem(clickRightHtml, "makeAsTitle","设为模具标题");
        this.addItem(clickRightHtml, "makeAsEdge","设为模具控制框");
        this.addItem(clickRightHtml, "makeAsTitleZone","设为模具标题区域");
        this.addItem(clickRightHtml, "makeAsLeadwire","设为模具引线");
        this.addItem(clickRightHtml,"symbolUnitHighSetting","模具图元高级设置");
        this.addItem(clickRightHtml, "switchState","切换状态");
    }

    addItem(clickRightHtml, subItem,title) {
        let editpropItem = document.getElementById(subItem);
        if (!editpropItem) {
            editpropItem = document.createElement('li');
            clickRightHtml.appendChild(editpropItem);
            editpropItem.id = subItem;
            editpropItem.innerHTML = title;

            editpropItem.addEventListener('click', function (evt) {
                clickRightHtml.style.display = "none";
                rightmenumainaction.RightMenuMainAction.act2Click(window.mainctl, evt, subItem);
                window.mainctl.forbidMouseMove = false;
            });
        }

        if (!window.mainctl.m_pRMenuINTF.chkItemCanDis(subItem)){
            clickRightHtml.removeChild(editpropItem);
        }
    }
}

export default { RMosUpSelGraphSvc }